package com.shiguiwu.springmybatis.spring.lifecycle.instance;

import com.shiguiwu.springmybatis.spring.lifecycle.definition.Pig;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.lang.Nullable;

import java.beans.PropertyDescriptor;

/**
 * @description: 6.1实例化中
 * 利用bean定义信息，借助反射，调用构造器，生成实例。构造器可有开发者决定
 * @author: stone
 * @date: Created by 2021/3/24 23:15
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.lifecycle.instance
 */
public class InstancingTests {

    public static void main(String[] args) {
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();

        factory.addBeanPostProcessor(new MySmartInstantiationAwareBeanPostProcessor());
        BeanDefinition stringBean = BeanDefinitionBuilder.genericBeanDefinition(String.class)
                .addConstructorArgValue("小猪佩奇")
                .getBeanDefinition();
        BeanDefinition integerBean = BeanDefinitionBuilder.genericBeanDefinition(Integer.class)
                .addConstructorArgValue(1)
                .getBeanDefinition();
        BeanDefinition pig = BeanDefinitionBuilder.genericBeanDefinition(Pig.class)
                .getBeanDefinition();
        factory.registerBeanDefinition("age", integerBean);
        factory.registerBeanDefinition("name", stringBean);
        factory.registerBeanDefinition("pig", pig);

        System.out.println(factory.getBean(Pig.class));



    }

}

